#include <iom128.h>
#include <inavr.h>
#include <stdio.h>
#include "type.h"
#include "uart.h"
#include "bitop.h"
#include "opcmd.h"
#include "led.h"
#include "1wslave.h"


void watchdog_init(void)
{
	__clear_watchdog_timer();
	WDTCR = ((1 << WDCE) | (1 << WDE));         
	WDTCR = ((1<< WDE) | (1 << WDP2) | (1 <<WDP1) | (1 <<WDP0)); //1.9s
}

void sys_init(void)
{

	__disable_interrupt ();

	delayms(20); 

	bit_set(DDRA,BIT1|BIT2);
	delayms(100);

	led_init();
	led_blink_fast(); //reset start

#if(UART_DEBUG)
	uart_init();
#endif  

	sensor_sys_init(0);


	w1s_init();

	led_blink_slow();

	//watchdog_init();

	__enable_interrupt ();



	return;
}

extern void test_modu_func(void);

void main(void)
{
	sys_init();

	test_modu_func();
	//while(1)
	//__clear_watchdog_timer();

	while(1)
	{
		w1s_wait_cmd();      
	}

}

#if 0
//test for watchdog for 1991ms.
void main(void)
{
	delayms(100);

	led_init();
	uart_init();

	F(("reset\r\n"));

	watchdog_init();


	led_on();
	delayms(500);
	led_off();
	delayms(500);

	while(1)
	{
		delayms(992);
		__clear_watchdog_timer(); 
	}
}

#endif
